package demo_0421;

public class Main03 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        IncerThread inerThread = new IncerThread(counter, 100);
        DecreThread DecreThread = new DecreThread(counter, 100);

        inerThread.start();
        DecreThread.start();

        //Thread.sleep(2000);
        //inerThread.join();
        //System.out.println(counter.getCount());
        //DecreThread.join();

        Thread.sleep(2000);
        System.out.println(counter.getCount());
    }
}

class IncerThread extends Thread {
    Counter counter;
    int times;

    public IncerThread(Counter counter, int times) {
        this.counter = counter;
        this.times = times;
    }

    public void run() {
        for (int i = 0; i < times; i++) {
            counter.increment();
        }
    }
}

class DecreThread extends Thread {
    Counter counter;
    int times;

    public DecreThread(Counter counter, int times) {
        this.counter = counter;
        this.times = times;
    }

    public void run() {
        for (int i = 0; i < times; i++) {
            counter.decrement();
        }
    }
}
